import re


def index():
    with open('./template/index.html') as f:
        content = f.read()
    info_from_mysql = 'I come from mysql'
    content = re.sub(r'\{%content%\}', info_from_mysql, content)
    return content


def center():
    with open('./template/center.html') as f:
        content = f.read()
    info_from_mysql = 'I come from mysql,too'
    content = re.sub(r'\{%content%\}', info_from_mysql, content)
    return content

URL_FUNC_DICT = {
    '/index.py':index,
    '/center.py':center
}

def application(env, start_response):
    status = '200 OK'
    response_header = [('Content-Type', 'text/html')]
    start_response(status, response_header)
    file_name = env['PATH_INFO']
    # if file_name == "/index.py":
    #     return index()
    # elif file_name == '/center.py':
    #     return center()
    # else:
    #     return 'Hello World!'
    func = URL_FUNC_DICT[file_name]
    return func()